package cn.buk.tms.eotms.entity;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import jakarta.persistence.*;

/**
 * Created by yfdai on 2017-10-10
 * 增值服务订单
 * @author yfdai
 */
@Entity
@Table(name = "vas_order",
        uniqueConstraints = @UniqueConstraint(
                name = "u_idx_vas_order",
                columnNames = {"enterprise_id", "order_no"}))
public class VasOrder {

    /**
     * 本地服务订单
     */
    public static final int VAS_ORDER_TYPE_LOCAL = 0;

    /**
     * VAAS平台服务订单
     */
    public static final int VAS_ORDER_TYPE_VAAS = 1;


    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    @Column(name = "enterprise_id", updatable = false)
    private int enterpriseId;

    /**
     * 服务单号
     */
    @Column(name = "order_no", length = 10)
    private String orderNo;

    /**
     * 外部订单号
     */
    @Column(name = "out_order_no", length = 32)
    private String externalOrderNo;

    /**
     * 订单类型
     * 0/null: 本地订单
     * 1: 机场服务订单（第三方订单(vaas)
     */
    @Column(name = "order_type")
    private Integer orderType;

    /**
     * 订单创建日期，搜索时会使用
     */
    @Temporal(TemporalType.DATE)
    @Column(name = "create_date", nullable = false)
    private Date createDate;

    /**
     * 关联的机票订单
     */
    @Column(name = "flight_order_id")
    private Integer flightOrderId;

    /**
     * 商品类型： 保险，门票等
     */
    @Column(name = "product_type", updatable = false)
    private int productType;
    /**
     * 增值服务产品的代码：TieInProduct.productCode
     */
    @Column(name = "product_code")
    private String productCode;

    @Column(name = "product_name")
    private String productName;

    /**
     * 客户类型
     * 0 - 代表散客
     * 1 - 代表企业客户
     */
    @Column(name = "customer_type")
    private int customerType;

    /**
     * 客户在系统中的id: 在t102中对应的ID
     */
    @ManyToOne
    @JoinColumn(name = "customer_id")
    private Customer customer;

    @Column(name = "customer_id", insertable = false, updatable = false)
    private Integer customerId;

    /**
     * 成本中心
     */
    @Column(name = "cost_center", length = 50)
    private String costCenter;

    @Column(name = "project_name", length = 50)
    private String projectName;

    /**
     * 创建此账单的用户名
     */
    @Column(length = 32)
    private String operator;

    /**
     * 订单状态
     * 0 - 待处理
     * 1 - 处理中
     * 2 - 已处理
     * 4 - 已取消
     */
    private int status;

    /**
     * 标价
     */
    private double price;

    /**
     * 折扣金额
     */
    private double discount;

    /**
     * 成本
     */
    private double cost;

    /**
     * 数量
     */
    private int count;

    /**
     * 利润 = count * (price - discount- cost)
     */
    private double profit;

    private Double total;


    /**
     * 该账单客户的付款方式
     * 1-现金；
     * 2-信用卡；
     * 4-支票；
     * 8-记账
     */
    @Column(name = "pay_type")
    private int payType;

    /**
     * 付款状态(只有付款类型非记账方式时才有用）
     * 0 or null 未支付
     * 1 已支付
     * 2 已销账 已支付（已销账，同步财务账单的状态）
     */
    @Column(name = "pay_status")
    private Integer payStatus;

    private String remark;


    /**
     * 联系人（代订人）
     */
    @Column(length = 20)
    private String linkman;

    @Column(length = 20, name = "link_phone")
    private String linkPhone;


    @OneToMany(mappedBy = "order", cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
    @OrderBy("name")
    private Set<VasOrderPassenger> passengers;

    @OneToMany(mappedBy = "order", cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
    @OrderBy("segOrder")
    private Set<VasOrderFlight> flights;

    /**
     * 对应的总订单id
     */
    @Column(name = "blanket_order_id")
    private Integer blanketOrderId;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "create_time", insertable = false, updatable = false)
    private Date createTime;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "last_update", insertable = false)
    private Date lastUpdate;


    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getProductCode() {
        return productCode;
    }

    public void setProductCode(String productCode) {
        this.productCode = productCode;
    }

    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    public int getEnterpriseId() {
        return enterpriseId;
    }

    public void setEnterpriseId(int enterpriseId) {
        this.enterpriseId = enterpriseId;
    }

    public Date getLastUpdate() {
        return lastUpdate;
    }

    public void setLastUpdate(Date lastUpdate) {
        this.lastUpdate = lastUpdate;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public int getCustomerType() {
        return customerType;
    }

    public void setCustomerType(Integer customerType) {
        this.customerType = customerType;
    }

    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public String getOperator() {
        return operator;
    }

    public void setOperator(String operator) {
        this.operator = operator;
    }

    public int getPayType() {
        return payType;
    }

    public void setPayType(int payType) {
        this.payType = payType;
    }

    public Integer getPayStatus() {
        return payStatus == null ? 0 : payStatus;
    }

    public void setPayStatus(Integer payStatus) {
        this.payStatus = payStatus;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public double getDiscount() {
        return discount;
    }

    public void setDiscount(double discount) {
        this.discount = discount;
    }

    public Set<VasOrderPassenger> getPassengers() {
        if (passengers == null) {
            passengers = new HashSet<>();
        }
        return passengers;
    }

    public void setPassengers(Set<VasOrderPassenger> passengers) {
        this.passengers = passengers;
    }

    public Double getTotal() {
        return total == null ? 0: total;
    }

    public void setTotal(Double total) {
        this.total = total;
    }

    public Integer getFlightOrderId() {
        return flightOrderId == null ? 0 : flightOrderId;
    }

    public void setFlightOrderId(Integer flightOrderId) {
        this.flightOrderId = flightOrderId;
    }

    public int getProductType() {
        return productType;
    }

    public void setProductType(int productType) {
        this.productType = productType;
    }

    public String getOrderNo() {
        return orderNo;
    }

    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }

    public String getCostCenter() {
        return costCenter;
    }

    public void setCostCenter(String costCenter) {
        this.costCenter = costCenter;
    }

    public String getLinkman() {
        return linkman;
    }

    public void setLinkman(String linkman) {
        this.linkman = linkman;
    }

    public String getLinkPhone() {
        return linkPhone;
    }

    public void setLinkPhone(String linkPhone) {
        this.linkPhone = linkPhone;
    }

    public String getProjectName() {
        return projectName;
    }

    public void setProjectName(String projectName) {
        this.projectName = projectName;
    }

    public Set<VasOrderFlight> getFlights() {
        if (flights == null) {
          flights = new HashSet<>();
        }
        return flights;
    }

    public void setFlights(Set<VasOrderFlight> flights) {
        this.flights = flights;
    }

    public int getOrderType() {
        return orderType == null ? 0 : orderType;
    }

    public void setOrderType(int orderType) {
        this.orderType = orderType;
    }

    public String getExternalOrderNo() {
        return externalOrderNo;
    }

    public void setExternalOrderNo(String externalOrderNo) {
        this.externalOrderNo = externalOrderNo;
    }

    public double getCost() {
        return cost;
    }

    public void setCost(double cost) {
        this.cost = cost;
    }

    public double getProfit() {
        return profit;
    }

    public void setProfit(double profit) {
        this.profit = profit;
    }

    public Integer getBlanketOrderId() {
        return blanketOrderId;
    }

    public void setBlanketOrderId(Integer blanketOrderId) {
        this.blanketOrderId = blanketOrderId;
    }

    public Integer getCustomerId() {
        return customerId;
    }
}
